package com.olddriver.crm.service.impl;

import com.olddriver.crm.domain.ClientMove;
import com.olddriver.crm.domain.Employee;
import com.olddriver.crm.mapper.ClientMoveMapper;
import com.olddriver.crm.page.PageResult;
import com.olddriver.crm.query.ClientMoveQueryObject;
import com.olddriver.crm.service.IClientMoveService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;

@Service
public class ClientMoveServiceImpl implements IClientMoveService {

    @Autowired
    private ClientMoveMapper clientMoveMapper;

    public int save(ClientMove clientMove){
        //设置录入时间
        clientMove.setInputTime(new Date());
        Employee inputUser = (Employee) SecurityUtils.getSubject().getPrincipal();
        //设置录入人
        clientMove.setInputUser(inputUser);
        return clientMoveMapper.save(clientMove);
    }

    public PageResult query(ClientMoveQueryObject qo) {
        int total = clientMoveMapper.queryTotal(qo);
        if (total == 0) {
            return new PageResult(total, Collections.emptyList());
        }
        return new PageResult(total, clientMoveMapper.queryRows(qo));
    }
}
